package yyds.sniarbtej.transformer.dbeaver;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import yyds.sniarbtej.transformer.BaseClassTransformer;
import yyds.sniarbtej.transformer.ClassRewriter;
import yyds.sniarbtej.utils.DebugUtil;

public class LicenseKey extends BaseClassTransformer {
    public String canTransformClassName() {
        return "com/dbeaver/model/license/embedded/LicenseKeyProviderEmbedded";
    }

    public byte[] rewrite(byte[] in) {
        byte[] out = transform(in, new ClassRewriter() {
            @Override
            public void rewriteMethod(MethodNode node) {
                InsnList insn;
                if ("getDecryptionKey".equals(node.name) && "(Lcom/dbeaver/lm/api/LMProduct;)Ljava/security/Key;".equals(node.desc)) {
                    insn = new InsnList();
                    insn.add(new MethodInsnNode(Opcodes.INVOKESTATIC, methodOverride, "D1", "()Ljava/security/Key;", false));
                    insn.add(new InsnNode(Opcodes.ARETURN));
                    node.instructions.insert(insn);
                }
            }
        });
        DebugUtil.dump(canTransformClassName(), out);
        return out;
    }
}
